package com.yhgarden.bbs.utils.common;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class ThreadUtils {
    private static ExecutorService fixedThreadPool;
    private static ScheduledExecutorService scheduledThreadPool;
    public static ExecutorService getExecutorService() {
        if (ThreadUtils.fixedThreadPool == null) {
            ThreadUtils.fixedThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        }
        return ThreadUtils.fixedThreadPool;
    }
    public static ExecutorService getExecutorService(int nThreads) {
        if (ThreadUtils.fixedThreadPool == null) {
            ThreadUtils.fixedThreadPool = Executors.newFixedThreadPool(nThreads);
        }
        return ThreadUtils.fixedThreadPool;
    }

    public interface FutureOperator<T>{
        T call();
    }

}
